<?php
define('DEBUG', 'on');
define('WEBPATH', __DIR__.'/webroot');
define('ROOT_PATH', __DIR__);

require __DIR__.'/vendor/autoload.php';
// 加载 env
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();

Swoole\Loader::vendorInit();
Swoole\Loader::addNameSpace('WebIM', __DIR__.'/src/');
Swoole::getInstance()->config->setPath(__DIR__.'/configs');
Swoole\Network\Server::setPidFile(__DIR__ . '/log/webim_server.pid');

Swoole\Network\Server::start(function(){
    $config = Swoole::getInstance()->config['webim'];

    $webim = new WebIM\Server($config);
    $webim->loadSetting(__DIR__ . "/swoole.ini"); //加载配置文件

    $server = new Swoole\Network\Server($config['server']['host'], $config['server']['port']);
    $server->setProcessName('webim-server');
    $server->setProtocol($webim);
    $server->run($config['swoole']);
});
